<?php
namespace app\shops\controller;

use think\Db;
use think\Model;

/**
 * 排课时段管理
 */
class Period extends Base
{
    /**
     * @throws
     * 时段列表
     * @return [type] [description]
     */
    public function index()
    {
        $list = Db("period")->where('shop_id',$this->shop_id)->select();
        $this->assign('list',$list);

        return $this->fetch();
    }


    /**
     * 添加时段
     */
    public function add()
    {
        // 异步提交数据
        if(request()->isPost()){

            $data['start_hour']         = input('start_hour');
            $data['start_minute']       = input('start_minute');
            $data['end_hour']           = input('end_hour');
            $data['end_minute']         = input('end_minute');
            $data['shop_id']            = $this->shop_id;

            $re = Db("period")->insert($data);
            if($re){
                $this->success("添加成功");
            }else{
                $this->error("网络错误");
            }

        }

        // $hour   = ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"];
        // $minute = ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","52","52","53","54","55","56","57","58","59"];
        $hour   = ["06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"];
        $minute = ["05","10","15","20","25","30","35","40","45","50","55"];

        $this->assign('hour',$hour);
        $this->assign('minute',$minute);

        return $this->fetch();
    }


    /**
     * @throws
     * 操作排课时段
     */
    public function deal()
    {
        // 更新数据
        if(request()->isPost()){

            $id = input("id");
            if($id <=0){
                $this->error("参数不完整");
            }

            input('is_show')        == null || $data['is_show']         = input('is_show');

            $re = Db("period")->where('shop_id',$this->shop_id)->where('id',$id)->update($data);
            if($re===false){
                $this->error("编辑失败");
            }
            $this->success("编辑成功");

        }

    }
    
}
